package com.longtop.perform.ar.web;

import java.util.Date;
import java.util.HashMap;

import com.longtop.framework.base.BaseAction;
import com.longtop.intelliweb.action.IActionContext;
import com.longtop.intelliweb.action.IInitContext;
import com.longtop.intelliweb.view.Dataset;
import com.longtop.perform.ar.service.AssignService;

public class ArDgMainListAction extends BaseAction {

	protected final String DATASET_MAIN = "Dataset_Main";

	/**
	 * 系统共用：初始化调用
	 */
	public void init(IInitContext context) {
		super.init(context);
	}

	/**
	 * 本页jsp：初始化业务数据(覆写父类方法)
	 */
	public void thisPageInit(IInitContext context) {

	}

	public void getMainAccts(IActionContext context, boolean isFirst) {
		Dataset dsMain = context.getDataset(DATASET_MAIN);
		HashMap map = new HashMap();
		AssignService assignService = this.getBean(AssignService.BEAN_ID);

		// 查询条件设置
		String custId = context.getElementValue("T_custId");
		String custName = context.getElementValue("T_custName");
		String downs = context.getElementValue("T_downOpenDate");
		String mainId = context.getElementValue("T_mainId");
		Date downOpenDate = null;
		if (downs != null && !"".equals(downs)) {
			downOpenDate = new Date(Long.parseLong(downs));
		}
		String ups = context.getElementValue("T_upOpenDate");
		Date upOpenDate = null;
		if (ups != null && !"".equals(ups)) {
			upOpenDate = new Date(Long.parseLong(ups));
		}
		String orgCode = context.getElementValue("orgCode");
		String isAllocate = context.getElementValue("T_isAllocate");

		map.put("mainId", mainId);
		map.put("custId", custId);
		map.put("custName", custName);
		map.put("downOpenDate", downOpenDate);
		map.put("upOpenDate", upOpenDate);
		map.put("orgCode", orgCode);
		map.put("isAllocate", isAllocate);

		map.put("tablenames", "T_I1_INFO_DG_MAIN");
		map.put("mastertablename", "T_AR_DG_MAIN");

		// 当前第几页
		if (isFirst) {
			dsMain.setPageNo(1);
		}

		assignService.queryForPageByIbatis("arAssignSql.selectMainList", null, map, dsMain, false);
	}

	public void queryMainAccts(IActionContext context) {
		getMainAccts(context, true);
	}

	public void loadMainAccts(IActionContext context) {
		getMainAccts(context, false);
	}

}
